package org.example.struct.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/12/4 10:47
 * @apiNote
 */

public class Test00205IsIsomorphic {
    public static void main(String[] args) {
        System.out.println(isIsomorphic("badc", "baba"));
    }


    public static boolean isIsomorphic(String s, String t) {
        Map<Character,Character> s2t = new HashMap<>();
        Map<Character,Character> t2s = new HashMap<>();
        int len = s.length();
        for(int i=0;i<len;i++){
            char x = s.charAt(i),y = t.charAt(i);
            if((s2t.containsKey(x) && s2t.get(x) != y) || (t2s.containsKey(y) && t2s.get(y) != x)){
                return false;
            }
            s2t.put(x,y);
            t2s.put(y,x);
        }
        return true;
    }
}
